#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsPixmapItem>
#include <QTimer>
#include <QLabel>
#include <QPushButton>
#include <QComboBox>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGroupBox>
#include <QFormLayout>
#include <QDateTime>
#include <QApplication>
#include <QMessageBox>
#include "gstreamer_pipeline.h"
#include <QOpenGLWidget>
#include <QOpenGLFunctions>

// 前向声明
class GStreamerPipeline;

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:

    void onNewFrameDataReceived(const FrameData &frameData);  // 新增高性能槽函数
    void onStartStopClicked();
    void onResolutionChanged(int index);
    void updatePerformanceInfo();

    //录制
    void onRecordClicked();
    //推流
    void onStreamClicked();


private:
    void setupUI();
    void setupConnections();
    void detectAvailableResolutions();
    void addResolution(int width, int height);

    // UI Components
    QGraphicsScene *m_scene;
    QGraphicsView *m_videoView;
    QGraphicsPixmapItem *m_pixmapItem;
    
    QPushButton *m_btnStartStop; //打开/关闭摄像头
    QPushButton *m_btnRecord;    //录制/关闭录制
    QPushButton *m_btnStream;    //推流/关闭推流
    
    QComboBox *m_cbResolution;
    QLabel *m_lblFPS; //FPS
    QLabel *m_lblStatus; //摄像头状态
    QLabel *m_lblRecordStatus; //录制状态
    QLabel *m_lblStreamStatus; //推流状态
    QLabel *m_lblGPUStatus;    //GPU使用状态
    QTimer *m_performanceTimer;

    // Core Components
    GStreamerPipeline *m_gstPipeline;
    
    int m_frameCount;
    qint64 m_lastFpsUpdate;
    QList<QPair<int, int>> m_availableResolutions; 


};

#endif // MAINWINDOW_H